package vue;

import java.awt.BorderLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

import modele.TrainAterrissage.Etat;
import modele.listener.*;
import modele.*;

/**
 * Panel correspondant a un ensemble Portes + Train
 * @author Jo
 *
 */
public class JPanelAtterrissage extends JPanel implements EtatTrainAterrissageListener, PorteListener {
	
	/**
	 * Pour le debug.
	 */
	private int id;
	
	public JLabel aterrissageImage= new JLabel();
	public JLabel portesImage= new JLabel();
	//La barre de progres n'est pas encore active, car secondaire
	JProgressBar progress1=new JProgressBar();
	
	public JPanelAtterrissage(BorderLayout b, int id) {
		super(b);
		
		this.id = id;
		
		aterrissageImage = new JLabel("", Display.ferme, JLabel.CENTER);
		portesImage = new JLabel("", Display.porte_fermee, JLabel.CENTER);
		this.add( portesImage, BorderLayout.PAGE_START );
		this.add( aterrissageImage, BorderLayout.CENTER );
		//this.add( progress1, BorderLayout.PAGE_END );
	}
	
	@Override
	public void etatChanged(EtatTrainAterrissageChangedEvent event) {
		
		//System.out.println("Etat changed : "+ event.getNewVolume());
		if(id==2) System.out.println(event.getNewVolume());
		
		if(event.getNewVolume() == Etat.FERME){
			setIcon_ferme();
		}
		else if(event.getNewVolume() == Etat.OUVERT){
			setIcon_ouvert();
		}
		else if(event.getNewVolume() == Etat.TRANSITIONDOWN){
			setIcon_transitiondown();
		}
		else if(event.getNewVolume() == Etat.TRANSITIONUP){
			setIcon_transitionup();
		}
	}
	
	public void setIcon_transitionup(){
		aterrissageImage.setIcon(Display.transitionup);
		progress1.setIndeterminate(true);
	}
	public void setIcon_transitiondown(){
		aterrissageImage.setIcon(Display.transitiondown);
		progress1.setIndeterminate(true);
	}
	public void setIcon_ouvert(){
		aterrissageImage.setIcon(Display.ouvert);
		progress1.setIndeterminate(false);
	}
	public void setIcon_ferme(){
		aterrissageImage.setIcon(Display.ferme);
		progress1.setIndeterminate(false);
	}

	@Override
	public void etatPortesChanged(PortesChangedEvent event) {
		if(event.getNewEtat() == Portes.Etat.FERMEES){
			portesImage.setIcon(Display.porte_fermee);
		}
		else if(event.getNewEtat() == Portes.Etat.OUVERTES){
			portesImage.setIcon(Display.porte_ouverte);
		}
		else if(event.getNewEtat() == Portes.Etat.TRANSITIONUP){
			portesImage.setIcon(Display.porte_up);
		}
		else if(event.getNewEtat() == Portes.Etat.TRANSITIONDOWN){
			portesImage.setIcon(Display.porte_down);
		}
	}
}
